package timing.ukulele.portal.dictionary;

import timing.ukulele.common.dictionary.CodeDescriptionEnum;

import java.util.Arrays;

public enum ParamTypeEnum implements CodeDescriptionEnum {
    SYSTEM(5, "系统类型"),
    BUSINESS(10, "业务类型");

    ParamTypeEnum(Integer code, String description) {
        this.code = code;
        this.description = description;
    }

    private Integer code;
    private String description;

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public static String getDescriptionByCode(Integer code) {
        if (code == null)
            return "未知";
        for (ParamTypeEnum typeEnum : values()) {
            if (typeEnum.code.equals(code)) {
                return typeEnum.description;
            }
        }
        return "未知";
    }

    public static Boolean hasValue(Integer code) {
        long count = Arrays.stream(values()).filter(item -> item.code.equals(code)).count();
        return count > 0;
    }

    @Override
    public String toString() {
        return code + "";
    }

    @Override
    public Integer getCode() {
        return this.code;
    }

    @Override
    public String getDescription() {
        return this.description;
    }
}
